package com.matt.controller.pad;

import com.matt.commons.dto.sso.StaffDTO;;
import com.matt.foundation.model.MemVerificationCache;
import com.matt.commons.model.StatusResponse;
import com.matt.foundation.utils.JsonValidateUtil;
import com.matt.foundation.vo.observation.ObservationChildrenListVo;
import com.matt.foundation.vo.observation.ObservationNewVo;
//import com.matt.service.DataTransferService;
import com.matt.service.ObservationNewService;
import com.matt.service.remoteCall.SsoCallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

import static com.matt.foundation.constant.RequestConstant.TICKET;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2018/3/15
 * *******************************
 */
@RestController
@RequestMapping("/pad/observation_new")
public class PadObservationNewController {

    @Autowired
    private MemVerificationCache cache;

    @Autowired
    private ObservationNewService observationNewService;

    @Autowired
    private SsoCallService ssoCallService;

//    @Autowired
//    private DataTransferService dataTransferService;

    @RequestMapping("/list_by_course_plan")
    public StatusResponse listByPlan(String coursePlanId, Integer category) {
        List<ObservationNewVo> observationList = observationNewService.getObservationByPlan(coursePlanId, category);
        return StatusResponse.success(observationList);
    }



    @RequestMapping("/add_record")
    public StatusResponse add(@RequestHeader(TICKET) String ticket, String childrenId, Integer category, String coursePlanId, String observationJson) {
        List list = JsonValidateUtil.readToList(observationJson, "观测点Json数据解析错误");
        StaffDTO baseInfo = cache.getStaff(ticket);
        String staffName = baseInfo.getRealName();
        Boolean result = observationNewService.addObservationRecord(childrenId, category, coursePlanId, list, cache.getStaffId(ticket), staffName, cache.getAreaId(ticket));
        return StatusResponse.success(result);
    }


    @RequestMapping("children_by_plan")
    public StatusResponse childrenByPlan(String coursePlanId, Integer category) {
        List<ObservationChildrenListVo> list = observationNewService.getChildrenByPlan(coursePlanId, category);
        return StatusResponse.success(list);
    }

    @RequestMapping("observation_upload")
    public StatusResponse observationUpload(Integer mediaType, MultipartFile[] files) {
        String imgUrl =  observationNewService.observationUpload(mediaType, files);
        return StatusResponse.success(imgUrl);
    }

//    @RequestMapping(value = "/transfer_observationById")
//    public StatusResponse transferObservationById(String coursePlanId){
//        Boolean result = dataTransferService.transferObservationById(coursePlanId);
//        return StatusResponse.success(result);
//    }
//
//    @RequestMapping(value = "/transfer_observationByDate")
//    public StatusResponse transferObservationByDate(String beginDate, String endDate){
//        Boolean result = dataTransferService.transferObservationByDate(beginDate,endDate);
//        return StatusResponse.success(result);
//    }
}
